package com.example.androidcomplete0102.ch12;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.example.androidcomplete0102.R;

public class ListViewResource extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_listviewarraylist);
		
		final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, 
				R.array.country, 
				android.R.layout.simple_expandable_list_item_1);
		
		ListView listview = (ListView)findViewById(R.id.ch12_listView);
		listview.setAdapter(adapter);
		
		listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Log.d("ListVieResource","position:"+position+"id:"+id);
				String text = "Select Item="+adapter.getItem(position);
				Toast.makeText(getApplicationContext(), 
						text, Toast.LENGTH_LONG).show();
			}
			
		});
	}
}
